package com.wkhyapp.lm.fragment;


import android.graphics.Color;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.loadmore.LoadMoreView;
import com.wkhyapp.lm.R;
import com.wkhyapp.lm.adapter.FansAdapter;
import com.wkhyapp.lm.adapter.GZAdapter;
import com.wkhyapp.lm.adapter.MemberAdapter;
import com.wkhyapp.lm.adapter.ShopAdapter;
import com.wkhyapp.lm.base.SuperFragment;
import com.wkhyapp.lm.contract.GZPresenter;
import com.wkhyapp.lm.contract.GZView;
import com.wkhyapp.lm.contract.IndexPagesPresenter;
import com.wkhyapp.lm.contract.IndexPagesView;
import com.wkhyapp.lm.http.vo.Fans;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.http.vo.GuanZhu;
import com.wkhyapp.lm.http.vo.Member;
import com.wkhyapp.lm.view.ShopActivity;
import com.wkhyapp.lm.weigit.EmptyView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class GZFragment extends SuperFragment<GZPresenter> implements GZView {


    @BindView(R.id.gz_refresh_view)
    SwipeRefreshLayout refresh_view;
    @BindView(R.id.gz_recycler_view)
    RecyclerView recycler_view;
    private GZAdapter gzAdapter;
    private List<Fans> fanses;
    private int mCurrentPage = 1;
    private View empty_view;

    @Override
    public void initUI() {
        fanses = new ArrayList<>();
        empty_view = EmptyView.getView(context,R.layout.empty_view,R.drawable.wuzhuangtai,"暂无关注");
        gzAdapter = new GZAdapter(R.layout.item_gz,fanses);
        refresh_view.setColorSchemeColors(Color.parseColor("#FFEC48"),Color.parseColor("#FFEC48"));
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recycler_view.setLayoutManager(manager);
        recycler_view.setAdapter(gzAdapter);
        refresh_view.setRefreshing(false);
        mPresenter.getData();
    }




    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        gzAdapter.setLoadMoreView(new LoadMoreView() {
            @Override
            public int getLayoutId() {
                return R.layout.view_index_load_more;
            }

            @Override
            protected int getLoadingViewId() {
                return com.chad.library.R.id.load_more_loading_view;
            }
            @Override
            protected int getLoadFailViewId() {
                return com.chad.library.R.id.load_more_load_fail_view;
            }
            @Override
            protected int getLoadEndViewId() {
                return com.chad.library.R.id.load_more_load_end_view;
            }
        });

        gzAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                mCurrentPage = mCurrentPage+1;
                mPresenter.getDataMore(mCurrentPage);

            }
        });
        refresh_view.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mCurrentPage = 1;
                mPresenter.getData();
            }
        });

        gzAdapter.setCallBack(new GZAdapter.callBack() {
            @Override
            public void action(Fans item) {
                goTo(ShopActivity.class,item.getId());
            }
        });
    }


    @Override
    public void setGuanzhu(List<Fans> list) {
        fanses.clear();
        if(list!=null&&list.size()>0){
            fanses.addAll(list);
            gzAdapter.removeFooterView(empty_view);
        }else{
            gzAdapter.removeFooterView(empty_view);
            gzAdapter.addFooterView(empty_view);
        }
        gzAdapter.notifyDataSetChanged();
        refresh_view.setRefreshing(false);
        gzAdapter.loadMoreComplete();
    }

    @Override
    public void setGuanzhuMore(List<Fans> list) {
        if(list.size()==0){
            gzAdapter.loadMoreComplete();
            gzAdapter.loadMoreEnd();
        }else{
            fanses.addAll(list);
            gzAdapter.notifyDataSetChanged();
            gzAdapter.loadMoreComplete();
        }
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_gz;
    }


    @Override
    protected GZPresenter createPresenter() {
        return mPresenter = new GZPresenter(this);
    }





}
